package com.lc.controller;

import com.github.pagehelper.PageInfo;
import com.lc.bean.Goods;
import com.lc.service.GoodsService;
import com.lc.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    // 分页+条件查询
    @GetMapping("/list")
    public R list(Goods goods,
                  @RequestParam(defaultValue = "1") Integer pageNum,
                  @RequestParam(defaultValue = "5") Integer pageSize) {

        PageInfo pageInfo = goodsService.list(goods,pageNum,pageSize);
        return R.ok(pageInfo);
    }

    @GetMapping("/del")
    public R del(Integer id) {
        goodsService.del(id);
        return R.ok();
    }

    @PostMapping("/save")
    public R save(Goods goods) {
        goodsService.save(goods);
        return R.ok();
    }

    // 根据id查询
    @GetMapping("/findById")
    public R findById(Integer id) {
        Goods goods = goodsService.findById(id);
        return R.ok(goods);
    }

    // 提交修改
    @PostMapping("/update")
    public R update(Goods goods) {
        goodsService.update(goods);
        return R.ok();
    }

    // 查询指定供应商下的所有商品，不需要分页


}
